package com.swlz.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.sql.SQLException;
import com.swlz.dao.MallOrderDetailDAO;
import com.swlz.dto.MallOrderDetailSearch;
import com.swlz.entity.MallOrderDetail;
import com.swlz.exception.CodeException;
import com.swlz.service.MallOrderDetailService;
import com.swlz.vo.MallOrderDetailVO;
import com.swlz.vo.PageVO;

/**
 * <pre>
 * 业务逻辑接口具体实现类
 * 商城订单详情
 * ClassName : com.swlz.service.impl.MallOrderDetailServiceImpl
 * Author : swlz
 * E-Mail : 2233875735@qq.com
 * Date : 2020-07-02 07:48:59
 * Version : 1.0
 * Copyright 2020 swlz.top Inc. All rights reserved. 
 * Warning: this content is only for internal circulation of the company. It is forbidden to divulge it or use it for other commercial purposes
 * </pre>
 **/
public class MallOrderDetailServiceImpl implements MallOrderDetailService {
	private static Logger log = LoggerFactory.getLogger(MallOrderDetailServiceImpl.class);
	
	private MallOrderDetailDAO mallOrderDetailDAO = new MallOrderDetailDAO();

	@Override
	public int add(MallOrderDetail mallOrderDetail) throws CodeException {
		try {
			return mallOrderDetailDAO.insertSelective(mallOrderDetail);
		} catch (SQLException e) {
			log.warn("添加商城订单详情错误",e);
			throw new CodeException(500, "添加商城订单详情错误",e);
		}
	}

	@Override
	public int update(MallOrderDetail mallOrderDetail) throws CodeException {
		try {
			return mallOrderDetailDAO.updateSelective(mallOrderDetail);
		} catch (SQLException e) {
			log.warn("修改商城订单详情错误",e);
			throw new CodeException(501, "修改商城订单详情错误",e);
		}
	}

	@Override
	public int delete(Long orderDetailId) throws CodeException {
		try {
			return mallOrderDetailDAO.deleteById(orderDetailId);
		} catch (SQLException e) {
			log.warn("删除商城订单详情错误",e);
			throw new CodeException(502, "删除商城订单详情错误",e);
		}
	}

	@Override
	public MallOrderDetail get(Long orderDetailId) throws CodeException {
		try {
			return mallOrderDetailDAO.selectById(orderDetailId);
		} catch (SQLException e) {
			log.warn("获取商城订单详情失败",e);
			throw new CodeException(503, "获取商城订单详情失败",e);
		}
	}

	@Override
	public PageVO<MallOrderDetail> page(MallOrderDetail mallOrderDetail, Integer current, Integer rowMax) throws CodeException {
		try {
			long total = mallOrderDetailDAO.countByModel(mallOrderDetail);
			PageVO<MallOrderDetail> page = new PageVO<>(total, current, rowMax);
			return page.setList(mallOrderDetailDAO.selectByModel(mallOrderDetail, page.getOffset(), page.getRowMax()));
		} catch (SQLException e) {
			log.warn("获取商城订单详情分页数据失败",e);
			throw new CodeException(504, "获取商城订单详情分页数据失败",e);
		}
	}
	@Override
	public PageVO<MallOrderDetailVO> page(MallOrderDetailSearch search) throws CodeException {
		try {
			long total = mallOrderDetailDAO.count(search);
			PageVO<MallOrderDetailVO> page = new PageVO<>(total, search.getPageNumber(), search.getPageSize());
			return page.setList(mallOrderDetailDAO.select(search, page.getOffset(), page.getRowMax()));
		} catch (SQLException e) {
			log.warn("获取商城订单详情分页数据失败",e);
			throw new CodeException(504, "获取商城订单详情分页数据失败",e);
		}
	}
	@Override
	public List<MallOrderDetail> list(MallOrderDetail mallOrderDetail, int len) {
		try {
			return mallOrderDetailDAO.selectByModel(mallOrderDetail, 0, len);
		} catch (SQLException e) {
			log.warn("获取商城订单详情列表数据失败",e);
			throw new CodeException(505, "获取商城订单详情列表数据失败",e);
		}	
	}



}
